<template>
  <el-dialog
    title="结算"
    :visible.sync="visible"
    :before-close="handleClose"
    width="20%"
  >
    <el-form ref="form" :model="form">
      <el-form-item
        label="请输入要结算的金额"
        prop="settlement_money"
        :rules="{ required: true, message: '请输入金额', trigger: 'blur' }"
      >
        <el-input-number
          v-model="form.settlement_money"
          :min="0"
          :precision="2"
          :step="1"
          :controls="false"
          label="描述文字"
        ></el-input-number>
      </el-form-item>
      <el-form-item>
        <span style="color:#F56C6C;"> 可结算金额：￥{{ val.cashmoney }} </span>
      </el-form-item>
    </el-form>

    <span slot="footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSumbit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { SETTLEMENTORDER } from "../../service";

export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    val: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      form: {
        settlement_money: 0
      }
    };
  },
  methods: {
    handleClose() {
      this.$emit("outDialog");
    },
    changes(page) {
      this.pages = page;
      this.getList();
    },
    async handleSumbit() {
      await this.$refs["form"].validate(valid => {
        if (valid) {
          SETTLEMENTORDER({
            flag: "save",
            member_id: this.val.member_id,
            settlement_money: this.form.settlement_money,
            type: 3,
            distribute_type: this.val.type,
            operator: "admin",
            store_id: this.val.store_id,
            distribute_lv_id: this.val.distribute_lv_id
          }).then(({ code, msg }) => {
            if (code === 200) {
              this.$emit("outDialog", true);
            }
            this.$message({
              message: msg,
              type: code === 200 ? "success" : "error"
            });
          });
        } else {
          return false;
        }
      });
    }
  }
};
</script>
